{% extends 'wancake/base_nav_frame.html' %}
{% load staticfiles %}
{% block content %}
  <div class="wb-productdetails-content">
    <div class="row panel panel-default">
      <div class="panel-heading">
        <h4>产品详情</h4>
      </div>
      <table class="table">
        <thead>
          <tr>
            <td>产品名称</td>
            <td>访问量</td>
            <td>用户数</td>
            <td>订购量</td>
            <td>内容总数</td>
            <td>播放时长</td>
            <td>播放次数</td>
            <td>周活跃度</td>
            <td>日活跃度</td>
          </tr>
        </thead>
        <tbody id="wb-product-details">
        </tbody>
      </table>
    </div>
  </div>
{% endblock %}
{% block jsscript %}
  <script type="text/javascript">
    $(document).ready(function(e) {
      $.ajax("./getproductdetails", {
        data : {
          session : "{{ session_id }}"
        }
        , type : "GET"
        , dataType : "json"
        , success : function(json) {
          console.log(JSON.stringify(json));
          if (json && json.data && json.data.list && json.data.list.length) {
            var list = json.data.list;
            var orderHistoryTBody = $("#wb-product-details");
            var length = list.length;

            var fmtValue = function(hd, sd) {
              return hd + "/" + sd;
            };
            for (var i = 0; i < length; i++) {
              var item = list[i];
              var tr = $('<tr />');
              $(tr).append($('<td />').text(item.cate_name));
              $(tr).append($('<td />').text(fmtValue(item.pv_hd, item.pv_sd)));
              $(tr).append($('<td />').text(fmtValue(item.users_hd, item.users_sd)));
              $(tr).append($('<td />').text(fmtValue(item.orders_hd, item.orders_sd)));
              $(tr).append($('<td />').text(fmtValue(item.content_count_hd, item.content_count_sd)));
              $(tr).append($('<td />').text(fmtValue(item.durations_hd, item.durations_sd)));
              $(tr).append($('<td />').text(fmtValue(item.play_count_hd, item.play_count_sd)));
              $(tr).append($('<td />').text(fmtValue(item.week_active_hd, item.week_active_sd)));
              $(tr).append($('<td />').text(fmtValue(item.today_active_hd, item.today_active_sd)));
              $(tr).appendTo(orderHistoryTBody);
            }
          }
        }, error : function(w, s, msg) {
          alert("服务器异常");
        }
      });
    });
  </script>
{% endblock %}